package com.wxyzz.canteenadmin.canteencard.cardlist.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.wxyzz.canteenadmin.canteencard.cardlist.param.CardListParam;
import com.wxyzz.canteenadmin.canteencard.cardlist.service.CardListService;
import com.wxyzz.canteencommon.common.R;
import com.wxyzz.canteencommon.entity.card.cardlist.CardList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * --- 代码敲烂 月薪过万 ---
 *
 * @author zhouhaoyu
 * @date 2024/10/9
 * @desc
 */
@RestController
@RequestMapping("cardlist/list")
public class CardListController {
    @Autowired
    private CardListService cardListService;

    /**
     * 查全部带分页
     */
    @GetMapping("/page")
    public R findAllAndPage(CardListParam cardListParam){
        System.out.println(cardListParam);
        PageInfo pageInfo = cardListService.findAllAndPage(cardListParam);
        return R.ok(pageInfo);
    }

    /**
     *根据ID删除
     */
    @PostMapping("/del")
    public R delCardListById(Integer cardId){
        System.out.println("接到的id" + cardId);
        cardListService.delCardListById(cardId);
        return R.ok();
    }


    /**
     * 添加卡券
     */
    @PostMapping("/add")
    public R addCardList(@RequestBody CardList cardList){
        cardListService.addCardList(cardList);
        return R.ok();
    }




    /**
     * 修改数据
     */
    @PostMapping("/update")
    public R updateCardList(@RequestBody CardList cardList){
        cardListService.updateCardList(cardList);
        return R.ok();
    }

    /**
     * 查询全部不带分页
     */
    @GetMapping("/findAll")
    public R findAllCard(){
        List<CardList> cardList = cardListService.findAllCard();
        return R.ok(cardList);
    }
}
